package game.ai.scene;

import game.ai.IEyeShotManager;
import game.ai.aoi.AoiAlgorithm;
import game.ai.aoi.AoiConstants;
import game.entity.Hero;

import java.util.Collection;

import lion.message.MyResponseMsg;

public class EyeShotManager implements IEyeShotManager {

	private SceneObject myself;

	/*** 视野范围内的可见对象存储容器 ********/
	protected SceneObjManager eyeShotObjManager;

	public EyeShotManager(SceneObject sceneObj) {
		this.myself = sceneObj;
		eyeShotObjManager = new SceneObjManager(myself.getHeedSceneObject());
	}

	@Override
	public boolean isContains(SceneObject other) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void sendMsg(MyResponseMsg msg) {
		Collection<Hero> cs = getEyeShotObjs(SceneObject.SceneObjType_Hero);
		if (cs == null || cs.isEmpty()) {
			if (this.myself instanceof SceneHero) {
				SceneHero hero = (SceneHero) myself;
				hero.sendMsg(msg);
			}
			return;
		}
		// NetTool.sendToCharacters(cs, msg);
	}

	@Override
	public void sendMsg(MyResponseMsg msg, Hero exclude) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onEnterScene(IScene scene, boolean broadcastToOther) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onLeaveScene(IScene scene) {
		AoiAlgorithm.getInstance().onAction(myself.getSceneRef().getAoiSpace(), myself.getId(), new short[] { myself.x, myself.y }, new byte[] { AoiConstants.MODE_DROP });
	}

	@Override
	public void onMove() {
		AoiAlgorithm.getInstance().onAction(myself.getSceneRef().getAoiSpace(), myself.getId(), new short[] { myself.x, myself.y }, myself.getAoiMode());
	}

	@SuppressWarnings("unchecked")
	@Override
	public <T> Collection<T> getEyeShotObjs(byte sceneObjType) {
		return (Collection<T>) eyeShotObjManager.getObjsCollection(sceneObjType);
	}

	@Override
	public <T> T getEyeShotObjs(byte clazz, int id) {
		return eyeShotObjManager.getObjsByClazzAndId(clazz, id);
	}

	@Override
	public void addInMyEyeShot(SceneObject obj, boolean msg) {
		if (obj == null) {
			return;
		}
		eyeShotObjManager.addObj(obj);
	}

	@Override
	public void removeFromMyEyeShot(SceneObject obj) {
		if (obj == null) {
			return;
		}
		eyeShotObjManager.removeVisibleObj(obj);
	}

	@Override
	public boolean testIsInMyEyeShot(short[] point) {
		return false;
	}

	@Override
	public int getObjCount() {
		return eyeShotObjManager.getObjCount();
	}

	@Override
	public Collection<SceneObject> getAllObjs() {
		return eyeShotObjManager.getAllSceneObjectCollection();
	}

}
